package arraysCommonMethods;

import java.util.Arrays;

/**
 * @ClassName ArraysFill
 * @Description 数组填充
 * @Author 李明忠
 * @Date 2025/5/21 22:30
 * @Version 1.0
 */
public class ArraysFill {
    public static void main(String[] args) {
        int[] arr = new int[5];
        int[] array = {1,2,3,4,5};
        int[] arr1 = new int[5];

        //第一种填充：填充所有数值
        System.out.println(Arrays.toString(arr));
        Arrays.fill(arr,10);//将arr数组所有数值填充为10；约等于初始化
        System.out.println(Arrays.toString(arr));

        //第二种填充：指定区间
        System.out.println("==================");
        System.out.println(Arrays.toString(arr1));
        Arrays.fill(arr1,2,5,10);
        System.out.println(Arrays.toString(arr1));

        //第三种：根据第二种实现对当元素的值进行修改
        System.out.println("========================");
        System.out.println(Arrays.toString(array));
        Arrays.fill(array,1,2,10);//[1,2)即：将下标为1的元素2改为10
        System.out.println(Arrays.toString(array));
    }
}
